package im.dhc.gitdiff.util;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

/**
 * @author songhaichao
 * @create 2020-07-13-10:25
 **/
public class FreemarkerUtil {

    public static void makeShell(String outDir,Object data) throws IOException, TemplateException {
        Configuration conf = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        conf.setDefaultEncoding("UTF-8");
        conf.setClassForTemplateLoading(FreemarkerUtil.class,"/");

        Template template = conf.getTemplate("ShellTem.ftl","UTF-8");
        FileOutputStream outputStream = new FileOutputStream(outDir+"/ht_deploy.sh");
        Writer out = new OutputStreamWriter(outputStream,"uTF-8");
        template.process(data,out);
        out.flush();
        out.close();

    }
}
